import { SubjectComponent } from "../../../../core/subject";
import Utils from "../../../../core/utils";
import BulletSpawner from "../game/bullet_spawner";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SpawnConfigItem extends SubjectComponent {
    spawn: BulletSpawner = null;
    @property(cc.EditBox)
    ebPrefab: cc.EditBox = null;
    @property(cc.EditBox)
    ebTag: cc.EditBox = null;

    lbSpawn: cc.Label = null;
    setData(spawn: BulletSpawner) {
        this.spawn = spawn;
        this.ebPrefab.string = this.spawn.node.name;
        this.ebTag.string = this.spawn.tag;

        let lbNode = new cc.Node();
        spawn.node.addChild(lbNode);
        this.lbSpawn = lbNode.addComponent(cc.Label);
        Utils.ChangeGroupRec("world", 3, lbNode);
        this.lbSpawn.fontSize = 20;
        this.lbSpawn.string = `${this.spawn.node.name}(${this.spawn.tag})`
    }
    onEdit() {
        this.spawn.node.name = this.ebPrefab.string;
        this.spawn.tag = this.ebTag.string;
        this.lbSpawn.string = `${this.spawn.node.name}(${this.spawn.tag})`
    }
    onClick() {
        this.emit("click", this);
    }
    onClickDel() {
        this.emit("del", this);
    }
};